home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / syscall / RCS / proc.c,v < prev    next >
Encoding:
Text File  |  1992-03-27  |  8.9 KB  |  395 lines

  1. head     1.7;
  2. branch   ;
  3. access   ;
  4. symbols  sprited:1.7.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.7
  10. date     90.01.03.17.30.48;  author douglis;  state Exp;
  11. branches 1.7.1.1;
  12. next     1.6;
  13.  
  14. 1.6
  15. date     89.07.31.17.41.10;  author douglis;  state Exp;
  16. branches ;
  17. next     1.5;
  18.  
  19. 1.5
  20. date     89.01.13.09.39.02;  author douglis;  state Exp;
  21. branches ;
  22. next     1.4;
  23.  
  24. 1.4
  25. date     89.01.02.13.59.31;  author douglis;  state Exp;
  26. branches ;
  27. next     1.3;
  28.  
  29. 1.3
  30. date     88.07.25.14.19.54;  author ouster;  state Exp;
  31. branches ;
  32. next     1.2;
  33.  
  34. 1.2
  35. date     88.06.21.11.14.59;  author ouster;  state Exp;
  36. branches ;
  37. next     1.1;
  38.  
  39. 1.1
  40. date     88.06.19.14.29.28;  author ouster;  state Exp;
  41. branches ;
  42. next     ;
  43.  
  44. 1.7.1.1
  45. date     91.12.08.17.38.01;  author kupfer;  state Exp;
  46. branches ;
  47. next     ;
  48.  
  49.  
  50. desc
  51. @@
  52.  
  53.  
  54. 1.7
  55. log
  56. @be more careful about migrating after MIGHOME signal.
  57. @
  58. text
  59. @/* 
  60.  * proc.c --
  61.  *
  62.  *    Miscellaneous run-time library routines for the Proc module.
  63.  *
  64.  * Copyright 1986 Regents of the University of California
  65.  * All rights reserved.
  66.  */
  67.  
  68. #ifndef lint
  69. static char rcsid[] = "$Header: /sprite/src/lib/c/syscall/RCS/proc.c,v 1.6 89/07/31 17:41:10 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  70. #endif not lint
  71.  
  72. #include <sprite.h>
  73. #include <status.h>
  74. #include <proc.h>
  75. #include <stdio.h>
  76.  
  77.  
  78. /*
  79.  *----------------------------------------------------------------------
  80.  *
  81.  * Proc_Exec --
  82.  *
  83.  *    Maps Proc_Exec calls into Proc_ExecEnv calls.  This routine
  84.  *    should not return unless the process cannot be exec'ed.
  85.  *
  86.  *
  87.  * Results:
  88.  *    Error status from Proc_ExecEnv, if any.
  89.  *
  90.  * Side effects:
  91.  *    Refer to Proc_ExecEnv kernel call & man page.
  92.  *
  93.  *----------------------------------------------------------------------
  94.  */
  95.  
  96. int
  97. Proc_Exec(fileName, argPtrArray, debugMe)
  98.     char *fileName;
  99.     char **argPtrArray;
  100.     Boolean debugMe;
  101. {
  102.     int status;
  103.     extern char **environ;
  104.     extern char **Proc_FetchGlobalEnv();    /* temporary!! */
  105.  
  106.     /*
  107.      * Install the system-wide environment if ours is non-existent.
  108.      */
  109.     if (environ == (char **) NULL) {
  110.     environ = Proc_FetchGlobalEnv();
  111.     }
  112.     status = Proc_ExecEnv(fileName, argPtrArray, environ, debugMe);
  113.     return(status);
  114. }
  115.  
  116. /*
  117.  *----------------------------------------------------------------------
  118.  *
  119.  * Proc_Wait --
  120.  *
  121.  *    The "normal" interface for waiting on child processes.
  122.  *    This procedure simply invokes the Proc_RawWait system call
  123.  *    and retries the call if the Proc_RawWait call aborted because
  124.  *    of a signal.  See the man page for details on what the kernel
  125.  *    call does.
  126.  *
  127.  * Results:
  128.  *    A standard Sprite return status.
  129.  *
  130.  * Side effects:
  131.  *    None.
  132.  *
  133.  *----------------------------------------------------------------------
  134.  */
  135.  
  136. ReturnStatus
  137. Proc_Wait(numPids, pidArray, block, procIdPtr, reasonPtr, statusPtr,
  138.     subStatusPtr, usagePtr)
  139.     int numPids;        /* Number of entries in pidArray below.
  140.                  * 0 means wait for ANY child. */
  141.     int pidArray[];        /* Array of pids to wait for. */
  142.     Boolean block;        /* TRUE means block;  FALSE means return
  143.                  * immediately if no children are dead. */
  144.     int *procIdPtr;        /* Return ID of dead/stopped process here,
  145.                  * if non-NULL. */
  146.     int *reasonPtr;        /* Return cause of death/stoppage here, if
  147.                  * non-NULL. */
  148.     int *statusPtr;        /* If process exited normally, return exit
  149.                  * status here (if non-NULL).  Otherwise
  150.                  * return signal # here. */
  151.     int *subStatusPtr;        /* Return additional signal status here,
  152.                  * if non-NULL. */
  153.     Proc_ResUsage *usagePtr;    /* Return resource usage info here,
  154.                  * if non-NULL. */
  155. {
  156.     ReturnStatus status;
  157.  
  158.     do {
  159.     status = Proc_RawWait(numPids, pidArray, block, procIdPtr,
  160.         reasonPtr, statusPtr, subStatusPtr, usagePtr);
  161.     } while (status == GEN_ABORTED_BY_SIGNAL);
  162.     return status;
  163. }
  164.  
  165.  
  166. /*
  167.  *----------------------------------------------------------------------
  168.  *
  169.  * Proc_Migrate --
  170.  *
  171.  *    The "normal" interface for invoking process migration.  This
  172.  *    performs extra checks against the process being migrated when
  173.  *    it is already migrated to a different machine.  
  174.  *
  175.  * Results:
  176.  *    A standard Sprite return status.
  177.  *
  178.  * Side effects:
  179.  *    The process is migrated home if it is not already home, then
  180.  *    it is migrated to the node specified.
  181.  *
  182.  *----------------------------------------------------------------------
  183.  */
  184.  
  185. ReturnStatus
  186. Proc_Migrate(pid, nodeID)
  187.     Proc_PID pid;
  188.     int         nodeID;
  189. {
  190.     ReturnStatus status;
  191.     int virtualHost;
  192.     int physicalHost;
  193.  
  194.     status = Proc_GetHostIDs(&virtualHost, &physicalHost);
  195.     if (status != SUCCESS) {
  196.     return(status);
  197.     }
  198.     if (pid == PROC_MY_PID) {
  199.     if (nodeID != physicalHost && nodeID != virtualHost) {
  200.         status = Sig_Send(SIG_MIGRATE_HOME, PROC_MY_PID, FALSE);
  201.         if (status != SUCCESS) {
  202.         return(status);
  203.         }
  204.     }
  205.     } else {
  206.     int i;
  207.     Proc_PCBInfo info;
  208.     /*
  209.      * Try to avoid the race condition for migrating other processes
  210.      * home.  This can be removed once the kernel does remote-to-remote
  211.      * migration directly.
  212.      */
  213. #define WAIT_MAX_TIMES 10
  214. #define WAIT_INTERVAL 1
  215.     (void) Sig_Send(SIG_MIGRATE_HOME, pid, TRUE);
  216.     for (i = 0; i < WAIT_MAX_TIMES; i++) {
  217.         status = Proc_GetPCBInfo(Proc_PIDToIndex(pid),
  218.                      Proc_PIDToIndex(pid), PROC_MY_HOSTID,
  219.                      sizeof(info),
  220.                      &info, (char *) NULL , (int *) NULL);
  221.         if (status != SUCCESS) {
  222.         return(status);
  223.         }
  224.         if (info.state != PROC_MIGRATED) {
  225.         break;
  226.         }
  227.         (void) sleep(WAIT_INTERVAL);
  228.     }
  229.     if (i == WAIT_MAX_TIMES) {
  230.         fprintf(stderr, "Unable to migrate process %x because it wouldn't migrate home.\n", pid);
  231.         return(FAILURE);
  232.     }
  233.     }
  234.     status = Proc_RawMigrate(pid, nodeID);
  235.     return(status);
  236. }
  237.  
  238. /*
  239.  *----------------------------------------------------------------------
  240.  *
  241.  * Proc_RemoteExec --
  242.  *
  243.  *    The "normal" interface for invoking remote exec.  This
  244.  *    performs extra checks against the process being migrated when
  245.  *    it is already migrated to a different machine.  
  246.  *
  247.  * Results:
  248.  *    This routine does not return if it succeeds.
  249.  *    A standard Sprite return status is returned upon failure.
  250.  *
  251.  * Side effects:
  252.  *    The process is migrated home if it is not already home, then
  253.  *    a remote exec is performed.
  254.  *
  255.  *----------------------------------------------------------------------
  256.  */
  257.  
  258. ReturnStatus
  259. Proc_RemoteExec(fileName, argPtrArray, envPtrArray, host)
  260.     char    *fileName;    /* The name of the file to exec. */
  261.     char    **argPtrArray;    /* The array of arguments to the exec'd 
  262.                  * program. */
  263.     char    **envPtrArray;    /* The array of environment variables for
  264.                  * the exec'd program. */
  265.     int        host;        /* ID of host on which to exec. */
  266. {
  267.     ReturnStatus status;
  268.     int virtualHost;
  269.     int physicalHost;
  270.  
  271.     status = Proc_GetHostIDs(&virtualHost, &physicalHost);
  272.     if (status != SUCCESS) {
  273.     return(status);
  274.     }
  275.     /*
  276.      * Save a double migration if the exec is local.
  277.      */
  278.     if (physicalHost != host) {
  279.     if (virtualHost != host) {
  280.         status = Sig_Send(SIG_MIGRATE_HOME, PROC_MY_PID, FALSE);
  281.         if (status != SUCCESS) {
  282.         return(status);
  283.         }
  284.     }
  285.     status = Proc_RawRemoteExec(fileName, argPtrArray, envPtrArray, host);
  286.     } else {
  287.     status = Proc_Exec(fileName, argPtrArray, envPtrArray, FALSE);
  288.     }
  289.     return(status);
  290. }
  291. @
  292.  
  293.  
  294. 1.7.1.1
  295. log
  296. @Initial branch for Sprite server.
  297. @
  298. text
  299. @d11 1
  300. a11 1
  301. static char rcsid[] = "$Header: /sprite/src/lib/c/syscall/RCS/proc.c,v 1.7 90/01/03 17:30:48 douglis Exp Locker: shirriff $ SPRITE (Berkeley)";
  302. @
  303.  
  304.  
  305. 1.6
  306. log
  307. @added Proc_RemoteExec
  308. @
  309. text
  310. @d11 1
  311. a11 1
  312. static char rcsid[] = "$Header: /sprite/src/lib/c/syscall/RCS/proc.c,v 1.5 89/01/13 09:39:02 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  313. d17 1
  314. d148 2
  315. d151 3
  316. a153 3
  317.      * Yes, there's a race condition here.  But then, migrating other
  318.      * processes is a little bizarre anyway.  This is at least an
  319.      * improvement until the kernel can handle it.
  320. d155 2
  321. d158 17
  322. @
  323.  
  324.  
  325. 1.5
  326. log
  327. @don't return a bad status if the SIG_MIGRATE_HOME
  328. signal fails.  The process may already have migrated.
  329. @
  330. text
  331. @d11 1
  332. a11 1
  333. static char rcsid[] = "$Header: /sprite/src/lib/c/syscall/RCS/proc.c,v 1.4 89/01/02 13:59:31 douglis Exp Locker: douglis $ SPRITE (Berkeley)";
  334. d155 54
  335. @
  336.  
  337.  
  338. 1.4
  339. log
  340. @added user level Proc_Migrate routine that checks to see if we're
  341. migrating from one foreign host to another, and sends process the
  342. SIG_MIGRATE_HOME signal first if so.
  343. @
  344. text
  345. @d11 1
  346. a11 1
  347. static char rcsid[] = "$Header: /sprite/src/lib/c/syscall/RCS/proc.c,v 1.3 88/07/25 14:19:54 ouster Exp Locker: douglis $ SPRITE (Berkeley)";
  348. d152 1
  349. a152 4
  350.     status = Sig_Send(SIG_MIGRATE_HOME, pid, TRUE);
  351.     if (status != SUCCESS) {
  352.         return(status);
  353.     }
  354. @
  355.  
  356.  
  357. 1.3
  358. log
  359. @Lint.
  360. @
  361. text
  362. @d11 1
  363. a11 1
  364. static char rcsid[] = "$Header: proc.c,v 1.2 88/06/21 11:14:59 ouster Exp $ SPRITE (Berkeley)";
  365. d104 55
  366. @
  367.  
  368.  
  369. 1.2
  370. log
  371. @Cleanup header usage.
  372. @
  373. text
  374. @d11 1
  375. a11 1
  376. static char rcsid[] = "$Header: proc.c,v 1.1 88/06/19 14:29:28 ouster Exp $ SPRITE (Berkeley)";
  377. a45 1
  378.     char *newEnv = NULL;
  379. @
  380.  
  381.  
  382. 1.1
  383. log
  384. @Initial revision
  385. @
  386. text
  387. @d11 1
  388. a11 1
  389. static char rcsid[] = "$Header: proc.c,v 2.1 88/02/21 15:50:27 douglis Exp $ SPRITE (Berkeley)";
  390. d14 3
  391. a16 2
  392. #include "sprite.h"
  393. #include "proc.h"
  394. @
  395.